<template>
  <div>
    <h1>列表动画</h1>
    <button @click="go">点击</button>
    <button @click="add">增加</button>
    <transition-group tag="ul" v-show="flag" name="student" appear>
      <li v-for="st in student" :key="st.id">
        {{ st.name }} <button @click="deleteItem(st.id)">删除</button>
      </li>
    </transition-group>
  </div>
</template>

<script>
export default {
  name: "List",
  data() {
    return {
      flag: true,
      student: [
        { id: "001", name: "lily" },
        { id: "002", name: "lucy" },
        { id: "003", name: "wangwu" },
        { id: "004", name: "zhaoliu" },
      ],
    };
  },
  methods: {
    go() {
      this.flag = !this.flag;
    },
    deleteItem(id) {
      this.student = this.student.filter((item) => item.id !== id);
    },
    add() {
      this.student.unshift({ id: Date.now(), name: "xiaoli" });
    },
  },
};
</script>

<style>
#good {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: palevioletred;
}
.student-enter,
.student-leave-to {
  opacity: 0;
  /* transform: translate(50px); */
}

.student-enter-active,
.student-leave-active {
  transition: all 0.7s linear;
}

/* 改变被删除元素不占空间的时候，缓动效果  */
.student-move {
  transition: all 0.5s linear;
}

/* 被删除的元素控制不占用空间 */
.student-leave-active {
  position: absolute;
}
</style>